package com.example.park2212.visitor

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.example.lib_base.mvvm.BaseActivity
import com.example.park2212.R
import com.example.park2212.databinding.ActivityVisitApproveBinding
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = "/app/visitor/VisitApproveActivity")
class VisitApproveActivity : BaseActivity<ActivityVisitApproveBinding,VisitorViewModel>() {

    @Autowired
    lateinit var vid:String

    override fun initView() {
        ARouter.getInstance().inject(this)
        viewModel.visitById(vid.toInt())

        binding.visitdetailBtn.setOnClickListener {
            val buttonId = binding.visitdetailRg.checkedRadioButtonId
            if (buttonId == R.id.visitdetail_yes){//通过
                viewModel.approveVisit(vid.toInt())
            }else{//拒绝
                viewModel.rejectVisit(vid.toInt())
            }
        }
    }

    override fun initData() {
        viewModel.visitByIdSuccess.observe(this){
            binding.bean=it
            if(it.visitStatus=="待审核"){
                binding.visitdetailGroup.visibility= View.VISIBLE
            }
        }

        viewModel.approveVisitSuccess.observe(this){
            ToastUtils.showLong("审核通过")
            finish()
        }

        viewModel.rejectVisitSuccess.observe(this){
            ToastUtils.showLong("驳回完成")
            finish()
        }
    }



}